package pl.edu.romanow.snippet

import net.liftweb.http.DispatchSnippet
import net.liftweb.common.Loggable
import xml.NodeSeq
import net.liftweb.util.Helpers._
import pl.edu.romanow.util.PopupUtil.AfterRefreshDo
import net.liftweb.http.js.{JsCmd, JsCmds}
import pl.edu.romanow.util.HTMLUtil

/**
 * Created by IntelliJ IDEA.
 * User: jar
 * Date: 25.03.12
 * Time: 11:48
 * To change this template use File | Settings | File Templates.
 */

class PopupSnipped extends DispatchSnippet with Loggable {

  val refresh: JsCmd = HTMLUtil.refreshParent;

  val close = JsCmds.Run("window.close();")


  override def dispatch = {
    case "redirect" =>
      "#script *" #>
        (if (!AfterRefreshDo.is.isEmpty) ((JsCmds.Run(AfterRefreshDo.is.openTheBox) & close))
        else (refresh & close))
    case _ => t: NodeSeq => t
  }


}